from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from ..server.controller import (
    LlmController,
    UserKnowledgeBaseController,
    UserSessionController,
)
from ..middleware import ChatHistoryMiddleware
from ..exception import register_exception_handler


def init(app: FastAPI):
    register_exception_handler(app)
    app.include_router(LlmController.router)
    app.include_router(UserKnowledgeBaseController.router)
    app.include_router(UserSessionController.router)
    app.add_middleware(ChatHistoryMiddleware)
    app.add_middleware(
        CORSMiddleware,
        allow_origins=["*"],
        allow_credentials=True,
        allow_methods=["*"],
        allow_headers=["*"],
    )
